﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ssp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            timer1.Start();
        }

        private async void timer1_Tick(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;

            if (dateTimePicker1.Value.Hour == now.Hour &&
                dateTimePicker1.Value.Minute == now.Minute &&
                dateTimePicker1.Value.Second == now.Second)
            {
                richTextBox1.Clear();
                string resultLog;
                try
                {
                    // 2. 异步等待 Spride.RunAsync() 完成，并获取日志字符串
                    //    (您不需要 .GetAwaiter().GetResult() 了)
                    resultLog = await Spride.RunAsync();
                }
                catch (Exception ex)
                {
                    // 3. 捕获所有可能的意外异常
                    resultLog = $"抓取过程中发生未处理的异常:\r\n{ex.ToString()}";
                }

                // 5. 关键：在 MessageBox 中显示最终的日志
                //    (为了防止日志太长，我们只显示最后1000个字符)
                if (resultLog.Length > 1000)
                {
                    resultLog = "...\r\n(日志过长，仅显示末尾部分)\r\n" + resultLog.Substring(resultLog.Length - 1000);
                }
                richTextBox1.Text = resultLog;
            }
        }
    }
}
